﻿@inject IWikiService WikiService
@inject IPopupService PopupService
@inject IChatApplicationService ChatApplicationService

@if (Value != null)
{
    <MSelect Items="Models"
             @bind-Value="@Value.ChatModel"
             ItemText="u => u.Item1"
             ItemValue="u => u.Item2"
             Label="选择对话基础模型"
             Dense
             Outlined></MSelect>

    <MTextarea Label="开场白"
               @bind-Value="Value.Opener"
               Outlined
               Placeholder="每一个对话开始前发生的默认内容，支持标准的Markdown语法和html。"
               Rows="5"
               RowHeight="15">
    </MTextarea>
    <MTextarea Label="提示词"
               @bind-Value="Value.Prompt"
               Outlined
               Placeholder="应用固定的提示词，可以修改该内容引导或定义对话角色，该内容会被固定再对话最上头。"
               Rows="5"
               RowHeight="15">
    </MTextarea>
    <MSlider @bind-Value="Value.Temperature"
             Label="温度"
             Min="0"
             Max="1"
             Step="0.1"
             ThumbLabel="@("always")"></MSlider>

    <MSlider @bind-Value="Value.MaxResponseToken"
             Label="最大响应Token"
             Min="200"
             Max="128000"
             Step="100"
             ThumbLabel="@("always")"></MSlider>

    <MTextField Label="引用上限"
                @bind-Value="Value.ReferenceUpperLimit"
                Outlined
                Placeholder="引用上限知识库引用最大上文token数。">
    </MTextField>
    <MSlider @bind-Value="Value.Relevancy"
             Label="匹配相似度"
             Min="0"
             Max="1"
             Step="0.05"
             ThumbLabel="@("always")"></MSlider>
    <MDialog Width="800">
        <ActivatorContent>
            <MButton Style="margin-top:10px;" @attributes="@context.Attrs" Block>选择知识库</MButton>
        </ActivatorContent>

        <ChildContent>
            <MCard>
                <MCardTitle Class="text-h5 grey lighten-2">
                    选择知识库
                </MCardTitle>

                <MCardText>
                    <div style="margin-bottom:8px;">
                        已选知识库：
                    </div>
                    @foreach (var item in Value.WikiIds)
                    {
                        <MChip Class="ma-2"
                               Close
                               Color="orange"
                               Label
                               Outlined
                               OnCloseClick="()=>RemoveWiki(item)">
                            @Wikis.Result.FirstOrDefault(x => x.Id == item)?.Name
                        </MChip>
                    }
                    <MDivider></MDivider>
                    <div style="margin-bottom:8px;">
                    </div>
                    @foreach (var item in Wikis.Result)
                    {
                        <MButton Class="mr-2"
                                 Outlined
                                 OnClick="()=>SelectWiki(item)">
                            @item.Name
                        </MButton>
                    }
                </MCardText>

                <MCardActions>
                    <MSpacer></MSpacer>
                </MCardActions>
            </MCard>
        </ChildContent>
    </MDialog>
    <MButton Style="margin-top:10px;" Color="#3370FF" OnClick="SubmitAsync" Block>保存修改</MButton>
}
